import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class homework_3 {
    public static void main(String[] args){
        String filepath="E:\\javaprojects\\homeworks\\src\\astring.txt";
        File file=new File(filepath);
        try(Scanner input=new Scanner(file)){
            StringBuilder contentBuilder=new StringBuilder();
            while (input.hasNextLine()){
                contentBuilder.append(input.nextLine());
            }
            String content=contentBuilder.toString();
            int maxLength=content.length();
            if(maxLength>1000){
                System.out.println("字符串太长了");
                return;
            }
            if(isAllDigits(content)){
                System.out.println("字符串长度为"+content.length());
                Scanner inputSub=new Scanner(System.in);
                int sub;
                int currentMax=0;
                int ans=1;
                do{
                    System.out.println("请输入子字符串长度");
                    sub=inputSub.nextInt();
                    if(sub<1||sub>content.length()){
                        System.out.println("输入的数字小于零或太大，请重新输入。");
                    }
                }while (sub<1||sub>content.length());
                for(int a=0;a<content.length()-sub+1;a++){
                    for(int b=0;b<sub;b++){
                        ans=ans*((int)content.charAt(a+b)-'0');
                    }
                    if(ans>currentMax){
                        currentMax=ans;
                    }
                    ans=1;
                }
                System.out.println("计算完成，文件中长度为"+sub+"的子字符串乘积最大值为："+currentMax);
                return;
            }
            else {
                System.out.println("文本中含有非数字，不进行计算");
            }
        }catch (FileNotFoundException e){
            System.out.println("文件未找到"+ e.getMessage());
            return;
        }

    }
    public static boolean isAllDigits(String string){
        for(int i=0;i<string.length();i++){
            if(!Character.isDigit(string.charAt(i))){
                return false;
            }
        }
        return true;
    }
}
